﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace XCI.Windows.Controls
{
    /// <summary>
    /// 线控件
    /// </summary>
    [System.ComponentModel.DesignerCategory("Code")]
    public class Line : UserControl
    {
        private Line.ControlStyle style;
        //private IContainer components;
        private PictureBox pictureBoxLine;
        private PictureBox pictureBoxTopLine;

        /// <summary>
        /// 线样式
        /// </summary>
        public Line.ControlStyle Style
        {
            get
            {
                return this.style;
            }
            set
            {
                this.style = value;
                this.pictureBoxTopLine.Visible = false;
                this.pictureBoxLine.Visible = false;
                if (this.style == Line.ControlStyle.Line)
                {
                    this.pictureBoxTopLine.Visible = true;
                    this.Height = this.pictureBoxTopLine.Height;
                }
                else
                {
                    this.pictureBoxLine.Visible = true;
                    this.Height = this.pictureBoxLine.Height;
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public Line()
        {
            this.InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        private void OnResize(object sender, EventArgs e)
        {
            this.pictureBoxLine.Left = this.Padding.Left;
            this.pictureBoxLine.Top = 0;
            this.pictureBoxLine.Width = this.Width - this.Padding.Left - this.Padding.Right;
            this.pictureBoxTopLine.Left = this.Padding.Left;
            this.pictureBoxTopLine.Top = 0;
            this.pictureBoxTopLine.Width = this.Width - this.Padding.Left - this.Padding.Right;
            this.Height = this.style == Line.ControlStyle.Label ? this.pictureBoxLine.Height : this.pictureBoxTopLine.Height;
        }

        /// <summary>
        /// 
        /// </summary>
        private void OnLoad(object sender, EventArgs e)
        {
            this.pictureBoxTopLine.Visible = false;
            this.pictureBoxLine.Visible = false;
            if (this.style == Line.ControlStyle.Line)
            {
                this.pictureBoxTopLine.Visible = true;
                this.Height = this.pictureBoxTopLine.Height;
            }
            else
            {
                this.pictureBoxLine.Visible = true;
                this.Height = this.pictureBoxLine.Height;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        protected override void OnPaddingChanged(EventArgs e)
        {
            base.OnPaddingChanged(e);
            this.OnResize(this, e);
        }

        //protected override void Dispose(bool disposing)
        //{
        //    //if (disposing && this.components != null)
        //    //    this.components.Dispose();
        //    base.Dispose(disposing);
        //}

        /// <summary>
        /// 
        /// </summary>
        private void InitializeComponent()
        {
            this.pictureBoxLine = new PictureBox();
            this.pictureBoxTopLine = new PictureBox();
            ((ISupportInitialize)this.pictureBoxLine).BeginInit();
            ((ISupportInitialize)this.pictureBoxTopLine).BeginInit();
            this.SuspendLayout();
            this.pictureBoxLine.Image = XCI.Windows.Properties.Resources.LineLabel;
            this.pictureBoxLine.Location = new Point(5, 0);
            this.pictureBoxLine.Name = "pictureBoxLine";
            this.pictureBoxLine.Size = new Size(90, 10);
            this.pictureBoxLine.TabIndex = 0;
            this.pictureBoxLine.TabStop = false;
            this.pictureBoxTopLine.Image = XCI.Windows.Properties.Resources.Line;
            this.pictureBoxTopLine.Location = new Point(0, 0);
            this.pictureBoxTopLine.Name = "pictureBoxTopLine";
            this.pictureBoxTopLine.Size = new Size(100, 2);
            this.pictureBoxTopLine.TabIndex = 1;
            this.pictureBoxTopLine.TabStop = false;
            this.AutoScaleMode = AutoScaleMode.Inherit;
            this.Controls.Add(this.pictureBoxTopLine);
            this.Controls.Add(this.pictureBoxLine);
            this.Name = "Line";
            this.Load += this.OnLoad;
            this.Resize += this.OnResize;
            ((ISupportInitialize)this.pictureBoxLine).EndInit();
            ((ISupportInitialize)this.pictureBoxTopLine).EndInit();
            this.ResumeLayout(false);
        }

        /// <summary>
        /// 线样式
        /// </summary>
        public enum ControlStyle
        {
            /// <summary>
            /// 线条
            /// </summary>
            Line,

            /// <summary>
            /// 带字符线条
            /// </summary>
            Label,
        }
    }
}